package top.toptimus.dto.printLog.tagPrintLog;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import top.toptimus.constValue.MeasureConsts;
import top.toptimus.dto.measure.MeasureItemDTO;
import top.toptimus.dto.measure.MeasureItemFacadeDTO;
import top.toptimus.dto.order.orderSync.orderCommit.OrderCommitDto;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@NoArgsConstructor
@AllArgsConstructor
@Data
public class TagPrintDTO {
    private String batchNo;
    private String orderId;
    private int orderNumber;
    private String styleId;
    private String styleNameCn;
    private String sytleFabricId;
    private String styleSizeCd;
    private String materialCode;
    private String materialComposition;
    private String materialNameCn;//面料描述名称
    private List<MeasureItemDTO> measureItemDTOS;   //  尺寸值
    private List<String> inventoryNos; //  成衣条码
    private String inventoryNo; //  成衣条码
    private String styleCategoryCd;
    private Double price;
//    private String saleInventoryId; //  货号

    public TagPrintDTO(OrderCommitDto orderCommitDto) {
        this.orderId = orderCommitDto.getOrderId();
        this.orderNumber = orderCommitDto.getOrderNumber().intValue();
        this.styleId = orderCommitDto.getStyleId();
        this.styleNameCn = orderCommitDto.getStyleNameCn();
        this.sytleFabricId = orderCommitDto.getStyleFabricId();
        this.materialNameCn = orderCommitDto.getMaterialNameCn();
        try {
            this.styleSizeCd = (
                    Objects.requireNonNull(
                            orderCommitDto.getStyleSizeCd()
                    )
            )
                    .replace(MeasureConsts.EGS_GROUP_SIZE_, "")
                    .replace(MeasureConsts.IGS_GROUP_SIZE_, "");
        } catch (Exception e) {
            e.printStackTrace();
        }
        this.materialCode = orderCommitDto.getMaterialCode();
        this.materialComposition = orderCommitDto.getComposition();
        this.styleCategoryCd = orderCommitDto.getStyleCategoryCd();
//        this.saleInventoryId = orderCommitDto.getSaleInventoryId();
    }

    public TagPrintDTO build(Double price) {
        this.price = price;
        return this;
    }

    public TagPrintDTO build(String batchNo, Double batchQuantiry) {
        this.batchNo = batchNo;
        this.orderNumber = batchQuantiry.intValue();
        return this;
    }

    /**
     * 构建量体值
     *
     * @param measureItemFacadeDTO 量体值
     * @return this
     */
    public TagPrintDTO build(MeasureItemFacadeDTO measureItemFacadeDTO) {
        this.measureItemDTOS = measureItemFacadeDTO.getMeasureItemDTOS();
        return this;
    }

    /**
     * 构建成衣条码
     *
     * @param inventoryNos 成衣条码
     * @return this
     */
    public TagPrintDTO build(List<String> inventoryNos) {
        this.inventoryNos = inventoryNos;
        return this;
    }

    /**
     * 构建成衣条码
     *
     * @param inventoryNo 成衣条码
     * @return this
     */
    public TagPrintDTO build(String inventoryNo) {
        this.inventoryNo = inventoryNo;
        return this;
    }

    /**
     * 生成吊牌信息
     *
     * @return 吊牌信息
     */
    public List<TagPrintSessionDTO> buildTagPrintSession() {
        return new ArrayList<TagPrintSessionDTO>() {{
            inventoryNos
                    .forEach(inventoryNo ->
                            add(
                                    new TagPrintSessionDTO(
                                            orderId,
                                            batchNo,
                                            orderNumber,
                                            styleId,
                                            styleNameCn,
                                            sytleFabricId,
                                            styleSizeCd,
                                            materialCode,
                                            styleId,
                                            inventoryNo
                                    )
                            )
                    );
        }};
    }
}
